//
//  ASMyPortraitVC.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 16/2/29.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASMyPortraitVC.h"
#import "ASMyportraitCell.h"

@interface ASMyPortraitVC ()

@property (nonatomic, strong) UITableView  *portraitTableView;
@property (nonatomic, strong) NSArray      *portraitArray;

@end

@implementation ASMyPortraitVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setLeftButtonWithImageName:@"ic_back" bgImageName:nil];
    self.strNavTitle = @"头像";
    
    _portraitArray = @[@"person_portrait_1", @"person_portrait_2", @"person_portrait_3", @"person_portrait_4", @"person_portrait_5"];
    
    [self initView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)initView
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    _portraitTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _portraitTableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    _portraitTableView.delegate = self;
    _portraitTableView.dataSource = self;
    _portraitTableView.backgroundColor = [UIColor whiteColor];
    _portraitTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_portraitTableView registerClass:[ASMyPortraitCell class] forCellReuseIdentifier:NSStringFromClass([ASMyPortraitCell class])];
    [self.view addSubview:_portraitTableView];
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_portraitArray count] / 2 + [_portraitArray count] % 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ASMyPortraitCell class])];
    
    ASMyPortraitCell *pCell = (ASMyPortraitCell *)cell;
    
    NSString *left = nil;
    NSString *right = nil;
    if ((indexPath.row * 2 + 1) > ([_portraitArray count] - 1))
    {
        left = nil;
    }
    else
    {
        left = [_portraitArray objectAtIndex:(indexPath.row * 2 + 1)];
    }
    
    if ((indexPath.row * 2 + 2) > ([_portraitArray count] - 1))
    {
        right = nil;
    }
    else
    {
        right = [_portraitArray objectAtIndex:(indexPath.row * 2 + 2)];
    }
    
    [pCell updateCellStatus:left rightImage:right];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 130.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}




@end




